
function testPrint(flag, pix) {
    if (flag) {
        console.log(pix, " 测试成功...")
    } else {
        console.log(pix, " 测试失败...")
    }
}

/**
 * 测试添加
 */
function doubleLinkedListTestAddCase01() {
    let linkedList = new DoubleLinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    let ex = ['A', 'B', 'C'];
    let result = eqArray(ex, linkedList.toArray())
    testPrint(result, "doubleLinkedListTestAddCase01")

    result = ex.length == linkedList.size;
    testPrint(result, "doubleLinkedListTestAddCase01")
}

doubleLinkedListTestAddCase01();

/**
 * 测试添加
 */
function doubleLinkedListTestAddCase02() {
    let linkedList = new DoubleLinkedList();
    linkedList.add('A')

    linkedList.addByIndex(0,'B')
    linkedList.addByIndex(0,'C')
    linkedList.addByIndex(1,'D')

    let ex = ['C','D','B','A'];
    let result = eqArray(ex, linkedList.toArray())
    testPrint(result, "doubleLinkedListTestAddCase02")

    result = ex.length == linkedList.size;
    testPrint(result, "doubleLinkedListTestAddCase02")

}
doubleLinkedListTestAddCase02()

function doubleLinkedListTestFindCase01() {
    let linkedList = new DoubleLinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    let index = linkedList.findIndexByEle('D');
    let result = index == 3;
    testPrint(result, "doubleLinkedListTestFindCase01--1")

    index = linkedList.findIndexByEle('C');
    result = index == 2;
    testPrint(result, "doubleLinkedListTestFindCase01--2")

    index = linkedList.findIndexByEle('B');
    result = index == 1;
    testPrint(result, "doubleLinkedListTestFindCase01--3")

    index = linkedList.findIndexByEle('A');
    result = index == 0;
    testPrint(result, "doubleLinkedListTestFindCase01--4")

    index = linkedList.findIndexByEle('G');
    result = index == -1
    testPrint(result, "doubleLinkedListTestFindCase01--5")
}
doubleLinkedListTestFindCase01();


function doubleLinkedListTestFindCase02() {
    let linkedList = new DoubleLinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')
    let ele = linkedList.findByIndex(0);
    let result = eqStr('A', ele)
    testPrint(result, "doubleLinkedListTestFindCase02")

    ele = linkedList.findByIndex(1);
    result = eqStr('B', ele)
    testPrint(result, "doubleLinkedListTestFindCase02")

    ele = linkedList.findByIndex(2);
    result = eqStr('C', ele)
    testPrint(result, "doubleLinkedListTestFindCase02")

    ele = linkedList.findByIndex(3);
    result = eqStr('D', ele)
    testPrint(result, "doubleLinkedListTestFindCase02")

}
doubleLinkedListTestFindCase02();


function doubleLinkedListTestFindCase03() {
    let linkedList = new DoubleLinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    let result1 = linkedList.contain('D');
    let result = result1 == true;
    testPrint(result, "doubleLinkedListTestFindCase03")

    result1 = linkedList.contain('C');
    result = result1 == true;
    testPrint(result, "doubleLinkedListTestFindCase03")

    result1 = linkedList.contain('B');
    result = result1 == true;
    testPrint(result, "doubleLinkedListTestFindCase03")

    result1 = linkedList.contain('A');
    result = result1 == true;
    testPrint(result, "doubleLinkedListTestFindCase03")

    result1 = linkedList.contain('E');
    result = result1 == false;
    testPrint(result, "doubleLinkedListTestFindCase03")

}

doubleLinkedListTestFindCase03();


function doubleLinkedListTestRemoveCase01() {
    let linkedList = new DoubleLinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    linkedList.remove('B');
    let ex = ['A','C','D'];
    let result = eqArray(ex, linkedList.toArray())
    testPrint(result, "doubleLinkedListTestRemoveCase01")

    linkedList.remove('A');
    ex = ['C','D'];
    testPrint(result, "doubleLinkedListTestRemoveCase01")

    linkedList.remove('D');
    ex = ['C'];
    testPrint(result, "doubleLinkedListTestRemoveCase01")
}
doubleLinkedListTestRemoveCase01();


function doubleLinkedListTestRemoveCase02() {
    let linkedList = new DoubleLinkedList();
    let result = "";
    try {
        linkedList.removeByIndex(0);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "doubleLinkedListTestRemoveCase02")
    }

    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    linkedList.removeByIndex(3);
    let ex = ['A','B','C'];
    result = eqArray(ex, linkedList.toArray())
    testPrint(result, "doubleLinkedListTestRemoveCase02")

    linkedList.removeByIndex(1);
    ex = ['A','C'];
    testPrint(result, "doubleLinkedListTestRemoveCase02")

    linkedList.removeByIndex(0);
    ex = ['C'];
    testPrint(result, "doubleLinkedListTestRemoveCase02")

    try {
        linkedList.removeByIndex(2);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "doubleLinkedListTestRemoveCase02")
    }
    linkedList.removeByIndex(0);

    try {
        linkedList.removeByIndex(0);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "doubleLinkedListTestRemoveCase02")
    }
}
doubleLinkedListTestRemoveCase02();


/**
 * 测试添加
 */
function linkedListTestAddCase01() {
    let linkedList = new LinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    let ex = ['A', 'B', 'C'];
    let result = eqArray(ex, linkedList.toArray())
    testPrint(result, "linkedListTestAddCase01")

    result = ex.length == linkedList.size;
    testPrint(result, "linkedListTestAddCase01")
}

linkedListTestAddCase01();

/**
 * 测试添加
 */
function linkedListTestAddCase02() {
    let linkedList = new LinkedList();
    let result = '';
    try {
        linkedList.addByIndex(0,'B')
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "linkedListTestAddCase02")
    }

    linkedList.add('A')

    linkedList.addByIndex(0,'B')
    linkedList.addByIndex(0,'C')
    linkedList.addByIndex(1,'D')

    let ex = ['C','D','B','A'];
    result = eqArray(ex, linkedList.toArray())
    testPrint(result, "linkedListTestAddCase02")

    result = ex.length == linkedList.size;
    testPrint(result, "linkedListTestAddCase02")

}
linkedListTestAddCase02()


function linkedListTestFindCase01() {
    let linkedList = new LinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    let index = linkedList.findIndexByEle('D');
    let result = index == 3;
    testPrint(result, "linkedListTestFindCase01--1")

    index = linkedList.findIndexByEle('C');
    result = index == 2;
    testPrint(result, "linkedListTestFindCase01--2")

    index = linkedList.findIndexByEle('B');
    result = index == 1;
    testPrint(result, "linkedListTestFindCase01--3")

    index = linkedList.findIndexByEle('A');
    result = index == 0;
    testPrint(result, "linkedListTestFindCase01--4")


    index = linkedList.findIndexByEle('J');
    result = index == -1;
    testPrint(result, "linkedListTestFindCase01--5")
}
linkedListTestFindCase01();


function linkedListTestFindCase02() {
    let linkedList = new LinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    let ele = linkedList.findByIndex(0);
    let result = eqStr('A', ele)
    testPrint(result, "linkedListTestFindCase02--1")

    ele = linkedList.findByIndex(1);
    result = eqStr('B', ele)
    testPrint(result, "linkedListTestFindCase02--2")

    ele = linkedList.findByIndex(2);
    result = eqStr('C', ele)
    testPrint(result, "linkedListTestFindCase02--3")

    ele = linkedList.findByIndex(3);
    result = eqStr('D', ele)
    testPrint(result, "linkedListTestFindCase02--4")


    try {
        ele = linkedList.findByIndex(5);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "linkedListTestFindCase02--5")
    }
}
linkedListTestFindCase02();


function linkedListTestFindCase03() {
    let linkedList = new LinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    let result1 = linkedList.contain('D');
    let result = result1 == true;
    testPrint(result, "linkedListTestFindCase03--1")

    result1 = linkedList.contain('C');
    result = result1 == true;
    testPrint(result, "linkedListTestFindCase03--2")

    result1 = linkedList.contain('B');
    result = result1 == true;
    testPrint(result, "linkedListTestFindCase03--3")

    result1 = linkedList.contain('A');
    result = result1 == true;
    testPrint(result, "linkedListTestFindCase03--4")

    result1 = linkedList.contain('E');
    result = result1 == false;
    testPrint(result, "linkedListTestFindCase03--5")

}

linkedListTestFindCase03();


function linkedListTestRemoveCase01() {
    let linkedList = new LinkedList();
    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    linkedList.remove('B');
    let ex = ['A','C','D'];
    let result = eqArray(ex, linkedList.toArray())
    testPrint(result, "doubleLinkedListTestRemoveCase01")

    linkedList.remove('A');
    ex = ['C','D'];
    testPrint(result, "doubleLinkedListTestRemoveCase01")

    linkedList.remove('D');
    ex = ['C'];
    testPrint(result, "doubleLinkedListTestRemoveCase01")
}
linkedListTestRemoveCase01();


function linkedListTestRemoveCase02() {
    let linkedList = new LinkedList();
    let result = "";
    try {
        linkedList.removeByIndex(0);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "doubleLinkedListTestRemoveCase02")
    }

    linkedList.add('A')
    linkedList.add('B')
    linkedList.add('C')
    linkedList.add('D')

    linkedList.removeByIndex(3);
    let ex = ['A','B','C'];
    result = eqArray(ex, linkedList.toArray())
    testPrint(result, "doubleLinkedListTestRemoveCase02")

    linkedList.removeByIndex(1);
    ex = ['A','C'];
    result = eqArray(ex, linkedList.toArray())
    testPrint(result, "doubleLinkedListTestRemoveCase02")

    linkedList.removeByIndex(0);
    ex = ['C'];
    result = eqArray(ex, linkedList.toArray())
    testPrint(result, "doubleLinkedListTestRemoveCase02")

    try {
        linkedList.removeByIndex(2);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "doubleLinkedListTestRemoveCase02")
    }
    linkedList.removeByIndex(0);

    try {
        linkedList.removeByIndex(0);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "doubleLinkedListTestRemoveCase02")
    }
}
linkedListTestRemoveCase02();